package com.zxh.zhenxihuan.service.impl;

import com.zxh.zhenxihuan.entity.z.Merchant;
import com.zxh.zhenxihuan.mapper.MerchantMapper;
import com.zxh.zhenxihuan.service.MerchantService;
import com.zxh.zhenxihuan.util.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;

import java.util.List;
import java.util.Map;

@Service("merchantService")
public class MerchantServiceImpl implements MerchantService {
    @Resource
    private MerchantMapper merchantMapper;
    @Override
    public Integer getSum() {
        return merchantMapper.getSum();
    }

    @Override
    public List<Merchant> getList(Integer start, Integer end) {
        List<Merchant> list=merchantMapper.getList(start,end);
        for(Merchant m:list){
            System.out.println(m);
        }
        return list;
    }

    @Override
    public Map<String,Object> getPage(Integer num, Integer count) {
        Integer pageNum=1;
        try {
            pageNum=Integer.valueOf(num);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        Integer pageCount=5;
        try {
            pageCount=Integer.valueOf(count);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        Page<Merchant> page =new Page();
        page.init(pageNum,pageCount,getSum());
        page.setList(getList(page.getRowNum(),pageCount));
        Map<String,Object> map = new HashMap<>();
        map.put("page",page);
        return map;
    }
}
